package com.zenith.zongheng.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zenith.zongheng.demo.domain.dto.LeaveFileDTO;
import com.zenith.zongheng.demo.domain.dto.LeaveFileSaveDTO;
import com.zenith.zongheng.demo.api.LeaveFileService;
import com.zenith.zongheng.core.result.R;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author tangzx
 * @since 2021-12-07
 */
@RestController
@RequestMapping("/leaveFile")
public class LeaveFileController {

    @Autowired
    @Reference
    private LeaveFileService leaveFileService;

    /**
     * 上传附件，但是要点击办理之后才上传
     *
     * @param leaveInfoId id
     * @param uploadFile  file
     * @return null
     * @author: wuyue
     */
    @PostMapping("/save")
    public R<Object> createLeaveFile(
            @RequestParam("leave_info_id") Integer leaveInfoId,
            @RequestParam("upload_file") MultipartFile uploadFile
    ) {
        leaveFileService.uploadFile(leaveInfoId, uploadFile);
        return R.ok();
      }
    @PostMapping("/update")
    public R<Object> updateLeaveFile(@RequestBody LeaveFileSaveDTO dto) {
        leaveFileService.updateLeaveFile(dto);
        return R.ok();
    }
    @PostMapping("/delete")
    public R<Object> deleteLeaveFile(@RequestBody Long... ids) {
        leaveFileService.deleteLeaveFile(ids);
        return R.ok();
    }
    @GetMapping("/getById/{id}")
    public R<Object> getById(@PathVariable Long id) {
        return R.ok(leaveFileService.getById(id));
    }

    @PostMapping("/list")
    public R<Object> list(@RequestBody(required = false) LeaveFileDTO dto) {
        return R.ok(leaveFileService.queryPage(dto));
    }

}

